import Main from "@/view/main/main";
import parentView from "@/components/parent-view";
import router from "@/router";
import store from "@/store";
import {getCookieObj,getCookie} from "@/libs/util";
import i18n from "./locale";

let configRouter = [
  {
    path: "/",
    name: "index",
    meta: {
      title: i18n.t('router.index'),
      hideInMenu: true
    },
    component: () => import("@/view/index/index.vue")
  },
  {
    path: "/sns-login",
    name: "sns-login",
    meta: {
      title: "Login - SNS登录",
      hideInMenu: true,
    },
    component: () => import("@/view/sns-login/sns-login.vue")
  },
  {
    path: "/ps-login",
    name: "ps-login",
    meta: {
      title: "Login - PS登录",
      hideInMenu: true,
    },
    component: () => import("@/view/sns-login/ps-login.vue")
  },
  {
    path: "/mm-login",
    name: "mm-login",
    meta: {
      title: "Login - MM登录",
      hideInMenu: true,
    },
    component: () => import("@/view/sns-login/mm-login.vue")
  },
  {
    path: "/xd-login",
    name: "xd-login",
    meta: {
      title: "Login - 登录",
      hideInMenu: true,
    },
    component: () => import("@/view/xd-login/xd-login.vue")
  },
  {
    path: '/401',
    name: 'error_401',
    meta: {
      hideInMenu: true
    },
    component: () => import('@/view/error-page/401.vue')
  },
  {
    path: '/500',
    name: 'error_500',
    meta: {
      hideInMenu: true
    },
    component: () => import('@/view/error-page/500.vue')
  },
  {
    path: '*',
    name: 'error_404',
    meta: {
      hideInMenu: true
    },
    component: () => import('@/view/error-page/404.vue')
  },
];

let permissionConfigRouter = [
  {
    path: "/main",
    name: "xd-home-management",
    meta: {
      title: "首页管理",
      icon: "md-speedometer",
      access: ["BEHQADMIN"]
    },
    component: Main,
    children: [
      {
        path: "/xd-home",
        name: "xd-home",
        meta: {
          icon: "md-speedometer",
          title: "首页",
          access: ["BEHQADMIN"]
        },
        component: () => import("@/view/xd-home/xd-home.vue")
      }
    ]
  },
  {
    path: "/main",
    name: "xd-settle-manage",
    meta: {
      title: i18n.t('router.xd-settle-manage'),
      icon: "md-speedometer",
      access: ["BEHQADMIN"],
    },
    component: Main,
    children: [
      {
        path: "/xd-settle",
        name: "xd-settle",
        meta: {
          icon: "md-speedometer",
          title: i18n.t('router.xd-settle'),
          access: ["BEHQADMIN"],
          message: 0,
        },
        component: () => import("@/view/xd-settle/xd-settle.vue")
      }
    ]
  }
];

let routers = configRouter.concat(permissionConfigRouter);
router.addRoutes(routers);

let token = getCookie("token");
if (!token || token == "undefined") {
  store.commit('setRouter',routers);
}

router.beforeEach((to, from, next) => {
  router.customBeforeEach(to, from, next, store.state.app.routers,configRouter);
});

router.afterEach(to => {
  router.customAfterEach(to);
});

export default router;
